package pt.iscte.dcti.es.rhplus.gestao;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 * Servlet implementation class for Servlet: Gestor
 *
 */
@SuppressWarnings("serial")
 public class Gestor extends javax.servlet.http.HttpServlet implements javax.servlet.Servlet {
	
	/* (non-Java-doc)
	 * @see javax.servlet.http.HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		HttpSession session = request.getSession();
		String gestor = (String) request.getParameter("gestor");
        
		if(gestor.equals(Gestor.UTENTES))
        	getServletConfig().getServletContext().
        		getRequestDispatcher("/GestorDeUtentes").forward(request, response);
        else if(gestor.equals(Gestor.COLABORADORES))
        	getServletConfig().getServletContext().
        		getRequestDispatcher("/GestorDeColaboradores").forward(request, response);
        else if(gestor.equals(Gestor.SERVICOS))
        	getServletConfig().getServletContext().
        		getRequestDispatcher("/GestorDeServicos").forward(request, response);
        else if(gestor.equals(Gestor.SISTEMA))
        	getServletConfig().getServletContext().
        		getRequestDispatcher("/GestorDeSistema").forward(request, response);
        else{
        	IllegalArgumentException illegal_argument_exception = new IllegalArgumentException(); 
        	session.setAttribute("excepcao", illegal_argument_exception.toString());
        	response.sendRedirect("/RHPlus/mostra_erro.jsp");
        }
	}  	
	
	/* (non-Java-doc)
	 * @see javax.servlet.http.HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}
	
	public static final String UTENTES = "gestor_de_utentes";
	public static final String COLABORADORES = "gestor_de_colaboradores";
	public static final String SERVICOS = "gestor_de_servicos";
	public static final String SISTEMA = "gestor_de_sistema";
}